// ColorSettingsDialog.cpp : implementation file
//

#include "stdafx.h"
#include "OpenGL.h"
#include "ColorSettingsDialog.h"
#include "afxdialogex.h"


// ColorSettingsDialog dialog

IMPLEMENT_DYNAMIC( CColorSettingsDialog, CDialogEx )

CColorSettingsDialog::CColorSettingsDialog( CWnd* pParent /*=NULL*/ )
	: CDialogEx( CColorSettingsDialog::IDD, pParent )
    , objectColor( 0 )
    , backgroundColor( 0 )
    , vertexNormalColor( 0 )
    , faceNormalColor( 0 )
    , boundingBoxColor( 0 )
    , overrideWireframeColor( 0 )
{
    // sets default values for all the colors
    restoreDefaults( );
}


CColorSettingsDialog::~CColorSettingsDialog( )
{
}


void CColorSettingsDialog::DoDataExchange( CDataExchange* pDX )
{
    CDialogEx::DoDataExchange( pDX );
    DDX_Control( pDX, IDC_OBJECT_COLOR_BUTTON, objectColorControl );
    DDX_Control( pDX, IDC_BACKGROUND_COLOR_BUTTON, backgroundColorControl );
    DDX_Control( pDX, IDC_MFCCOLORBUTTON4, vertexNormalColorControl );
    DDX_Control( pDX, IDC_MFCCOLORBUTTON5, faceNormalColorControl );
    DDX_Control( pDX, IDC_MFCCOLORBUTTON6, boundingBoxColorControl );
    DDX_Control( pDX, IDC_OVERRIDE_WIREFRAME_COLOR, overrideWireframeColorControl );
}


BEGIN_MESSAGE_MAP( CColorSettingsDialog, CDialogEx )
    ON_BN_CLICKED(IDOK, &CColorSettingsDialog::OnBnClickedOk)
    ON_BN_CLICKED(IDC_RESTORE_DEFAULTS, &CColorSettingsDialog::OnBnClickedRestoreDefaults)
    ON_BN_CLICKED(IDC_OVERRIDE_WIREFRAME_COLOR, &CColorSettingsDialog::OnBnClickedOverrideWireframeColor)
END_MESSAGE_MAP( )


// ColorSettingsDialog message handlers


BOOL CColorSettingsDialog::OnInitDialog( )
{
    COLORREF colorRef = 0x00000000; // 0x00bbggrr

    CDialogEx::OnInitDialog( );

    // TODO:  Add extra initialization here
    objectColorControl.SetColor( objectColor );
    backgroundColorControl.SetColor( backgroundColor );
    vertexNormalColorControl.SetColor( vertexNormalColor );
    faceNormalColorControl.SetColor( faceNormalColor );
    boundingBoxColorControl.SetColor( boundingBoxColor );
    overrideWireframeColorControl.SetCheck( overrideWireframeColor );

    return TRUE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
}


void CColorSettingsDialog::OnBnClickedOk( )
{
    objectColor       = objectColorControl.GetColor( );
    backgroundColor   = backgroundColorControl.GetColor( );
    vertexNormalColor = vertexNormalColorControl.GetColor( );
    faceNormalColor   = faceNormalColorControl.GetColor( );
    boundingBoxColor  = boundingBoxColorControl.GetColor( );

    CDialogEx::OnOK();
}


void CColorSettingsDialog::OnBnClickedRestoreDefaults( )
{
    restoreDefaults( );

    objectColorControl.SetColor( objectColor );
    backgroundColorControl.SetColor( backgroundColor );
    vertexNormalColorControl.SetColor( vertexNormalColor );
    faceNormalColorControl.SetColor( faceNormalColor );
    boundingBoxColorControl.SetColor( boundingBoxColor );
    overrideWireframeColorControl.SetCheck( overrideWireframeColor );

//    Invalidate( );
}


void CColorSettingsDialog::OnBnClickedOverrideWireframeColor()
{
    overrideWireframeColor = !overrideWireframeColor;
//    overrideWireframeColorControl.SetCheck( overrideWireframeColor );
}
